/**
 * Copyright (c) subnew
 * Licensed under the GPL;
 * @email:joseanluo@gmail.com
 * @Title: SysRole.java
 * @Package com.subnew.copyman.modules.sys.entity
 */
package com.subnew.mango.modules.sys.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import com.subnew.mango.frame.dao.entity.BaseEntity;


/**
 * 系统角色实体
 * 
 * @author JoseanLuo
 * @date 2014年9月17日 上午11:54:33
 * @version V1.0<br>
 *          V2.0 关联关系加入 20141223 
 */
@Entity
@Table(name = "sys_role")
public class SysRole extends BaseEntity {
	/**
	 * 角色名
	 */
	private String name;
	/**
	 * 角色编码
	 */
	private String code;
	/**
	 * 角色描述
	 */
	private String memo;
	/**
	 * 角色菜单
	 */
	private Set<SysMenu> sysMenus = new HashSet<SysMenu>(0);
	/**
	 * 角色用户
	 */
	private Set<SysOperator> sysOperators = new HashSet<SysOperator>(0);
	/**
	 * 角色组织
	 */
	private Set<SysGroup> sysGroups = new HashSet<SysGroup>(0);

	@Column(name = "name")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "code", length = 36)
	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "memo")
	public String getMemo() {
		return this.memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "sys_role_menu", joinColumns = { @JoinColumn(name = "role_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "menu_id", nullable = false, updatable = false) })
	public Set<SysMenu> getSysMenus() {
		return this.sysMenus;
	}

	public void setSysMenus(Set<SysMenu> sysMenus) {
		this.sysMenus = sysMenus;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "sys_operator_role", joinColumns = { @JoinColumn(name = "role_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "operator_id", nullable = false, updatable = false) })
	public Set<SysOperator> getSysOperators() {
		return this.sysOperators;
	}

	public void setSysOperators(Set<SysOperator> sysOperators) {
		this.sysOperators = sysOperators;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "sys_group_role", joinColumns = { @JoinColumn(name = "role_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "group_id", nullable = false, updatable = false) })
	public Set<SysGroup> getSysGroups() {
		return this.sysGroups;
	}

	public void setSysGroups(Set<SysGroup> sysGroups) {
		this.sysGroups = sysGroups;
	}

}
